{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python_defaultSpec_1600400578389",
   "display_name": "Python 3.8.5 64-bit"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "source": [
    "在提交记录里面找了一个大佬写的代码，完全看不懂。。。"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution:\n",
    "    def permuteUnique(self, nums: List[int]) -> List[List[int]]:\n",
    "        res = []\n",
    "        n = len(nums)\n",
    "        def dfs(x):\n",
    "            if x == n - 1:\n",
    "                res.append(nums[:])\n",
    "                return\n",
    "            dic = set()\n",
    "            for i in range(x, n):\n",
    "                if nums[i] in dic: continue\n",
    "                print(x, i, nums)\n",
    "                dic.add(nums[i])\n",
    "                print(dic)\n",
    "                nums[i], nums[x] = nums[x], nums[i]\n",
    "                dfs(x+1)\n",
    "                nums[i], nums[x] = nums[x], nums[i]\n",
    "        dfs(0)\n",
    "        return res        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "0 0 [1, 1, 2]\n{1}\n1 1 [1, 1, 2]\n{1}\n1 2 [1, 1, 2]\n{1, 2}\n0 2 [1, 1, 2]\n{1, 2}\n1 1 [1, 1, 2]\n{1}\n1 2 [1, 1, 2]\n{1, 2}\n"
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[[1, 1, 2], [1, 1, 2], [1, 1, 2], [1, 1, 2]]"
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "source": [
    "Solution().permuteUnique([1, 1, 2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}